package cate.game.play.config.skill;

import cate.common.table.d.GDSkill;
import cate.common.table.fight.skill.row.SkillBaseRow;
import cate.common.table.fight.skill.row.SkillEnhanceRow;
import cate.common.util.XT;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@NoteClass(value = "技能配置",detail = "包括原始的row和一些可能被强化的字段")
public class SkillCfg {

    @NoteField("技能id")
    public int id;

    @NoteField("原始数据row")
    public SkillBaseRow row;

    @NoteField("汇总的强化配置")
    public SkillEnhance enhance = new SkillEnhance();


    public SkillCfg() {
    }

    public SkillCfg(SkillBaseRow row) {
        this.id = row.id;
        this.row = row;
    }

    public void enhance(SkillEnhanceRow enhanceRow){
        enhance.settle(enhanceRow);
    }

    public boolean isEffectType(String effectType) {
        return StringUtils.equals(effectType, this.row.effectType);
    }

    public boolean isHurtSkill(){
        return isEffectType(GDSkill.EffectType.伤害);
    }

    public boolean isSupportSkill() {
        return row.gain || isEffectType(GDSkill.EffectType.治疗) || isEffectType(GDSkill.EffectType.复活);
    }

    public boolean isType(int type) {
        return type == this.row.type;
    }

    public boolean containTag(String tag) {
        if (row.tags == null) {
            return false;
        }
        for (String s : row.tags) {
            if (StringUtils.equals(s, tag)) {
                return true;
            }
        }
        return false;
    }

    public boolean containTags(List<String> tags) {
        if (row.tags == null || tags == null) {
            return false;
        }
        for (String s : row.tags) {
            if (tags.contains(s)) {
                return true;
            }
        }
        return false;
    }


    public boolean getFeaturePhy() {
        return enhance.featurePhy == null ? row.featurePhy : enhance.featurePhy;
    }

    public boolean getFeatureMagic() {
        return enhance.featureMagic == null ? row.featureMagic : enhance.featureMagic;
    }

    public Byte getCSpecial() {
        return enhance.cSpecial == null ? row.cSpecial : enhance.cSpecial;
    }

    public Integer getCAttr() {
        return enhance.cAttr == null ? row.cAttr : enhance.cAttr;
    }

    public List<Byte> getCJobs(){
        return XT.mergeNew(row.cJobs,enhance.cJobs);
    }

    public List<Byte> getCCamps(){
        return XT.mergeNew(row.cCamps,enhance.cCamps);
    }

    public List<String> getCSkillTags(){
        return XT.mergeNew(row.cSkillTags,enhance.cSkillTags);
    }

    public List<String> getCBuffTags(){
        return XT.mergeNew(row.cBuffTags,enhance.cBuffTags);
    }

    public List<Integer> getSubSkills() {
        return XT.mergeNew(row.subSkills,enhance.exSubSkills);
    }

    public int getTargetNum() {
        return enhance.exTargetNum + row.targetNum;
    }

    public List<String> getCasterAttrs(){
        return XT.mergeNew(row.casterTempAttrs,enhance.exCasterAttrs);
    }

    public List<String> getBuffAddRules(){
        return XT.mergeNew(row.buffAddRules, enhance.exBuffAddRules);
    }

    public List<String> getPassiveBuffs(){
        return XT.mergeNew(row.passiveBuffs,enhance.exPassiveBuffs);
    }

    public int getCD() {
        return enhance.exCD + row.cd;
    }

    public byte getRetarget() {
        return enhance.retarget == null ? row.retarget : enhance.retarget;
    }
}
